package com.spring.utils.api_v4.dao;

import com.spring.utils.api_v4.pojo.salary.task.WageTask;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 工资任务管理器
 */
@Repository
public interface IWageTaskDao extends JpaRepository<WageTask, Integer> {

    @Transactional
    @Query(value = "update WageTask as t set t.state=?2 where t.state=?1", nativeQuery = true)
    @Modifying
    void updateState(int oldState, int newState);

    /**
     * 获取指定状态的任务列表
     * @param state
     * @return
     */
    List<WageTask> findByState(int state);

    /**
     * 判断是否存在指定状态的任务
     * @param state
     * @return
     */
    boolean existsByState(int state);
}
